package day05;
/*
    数组逆序
 */
public class ArrayTest3 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,9};

        System.out.println("逆序前：");
        PrintArray(arr);
        System.out.println("-----------");
        System.out.println("逆序后");
        reverse(arr);
        PrintArray(arr);
        System.out.println("-----------");
    }

    //逆序
    public static void reverse(int[] arr){
        for(int i=0;i<arr.length/2;i++){
            int temp = arr[i];
            arr[i] = arr[arr.length-1-i];
            arr[arr.length-1-i] = temp;
        }
    }

    //遍历
    public static void PrintArray(int[] arr){
        System.out.print("[ ");
        for(int i=0;i<arr.length;i++){
            if(i == arr.length-1){
                System.out.println(arr[arr.length-1]+" ]");
            }else{
                System.out.print(arr[i]+",");
            }
        }
    }
}
